home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Games / MAME / src / vidhrdw / seta.c < prev    next >
C/C++ Source or Header  |  2000-04-04  |  19KB  |  725 lines

  1. /***************************************************************************
  2.  
  3.                                 -= Seta Games =-
  4.  
  5.                     driver by    Luca Elia (eliavit@unina.it)
  6.  
  7.  
  8. Note:    if MAME_DEBUG is defined, pressing Z with:
  9.  
  10.         Q            shows layer 0
  11.         W            shows layer 1
  12.         A            shows the sprites
  13.  
  14.         Keys can be used togheter!
  15.  
  16.  
  17.                         [ 0, 1 Or 2 Scrolling Layers ]
  18.  
  19.     Each layer consists of 2 tilemaps: only one can be displayed at a
  20.     given time (the games usually flip continuously between the two).
  21.     The two tilemaps share the same scrolling registers.
  22.  
  23.         Layer Size:                1024 x 512
  24.         Tiles:                    16x16x4 (16x16x6 in some games)
  25.         Tile Format:
  26.  
  27.             Offset + 0x0000:
  28.                             f--- ---- ---- ----        Flip X
  29.                             -e-- ---- ---- ----        Flip Y
  30.                             --dc ba98 7654 3210        Code
  31.  
  32.             Offset + 0x1000:
  33.  
  34.                             fedc ba98 765- ----        -
  35.                             ---- ---- ---4 3210        Color
  36.  
  37.             The other tilemap for this layer (always?) starts at
  38.             Offset + 0x2000.
  39.  
  40.  
  41.                             [ 1024 Sprites ]
  42.  
  43.     Sprites are 16x16x4. They are just like those in "The Newzealand Story",
  44.     "Revenge of DOH" etc (tnzs.c). Obviously they're hooked to a 16 bit
  45.     CPU here, so they're mapped a bit differently in memory. Additionally,
  46.     there are two banks of sprites. The game can flip between the two to
  47.     do double buffering, writing to a bit of a control register(see below)
  48.  
  49.  
  50.         Spriteram_2 + 0x000.w
  51.  
  52.                         f--- ---- ---- ----        Flip X
  53.                         -e-- ---- ---- ----        Flip Y
  54.                         --dc b--- ---- ----        -
  55.                         ---- --98 7654 3210        Code (Lower bits)
  56.  
  57.         Spriteram_2 + 0x400.w
  58.  
  59.                         fedc b--- ---- ----        Color
  60.                         ---- -a-- ---- ----        ?Code (Upper Bits)?
  61.                         ---- --9- ---- ----        Code (Upper Bits)
  62.                         ---- ---8 7654 3210        X
  63.  
  64.         Spriteram   + 0x000.w
  65.  
  66.                         fedc ba98 ---- ----        -
  67.                         ---- ---- 7654 3210        Y
  68.  
  69.  
  70.  
  71.                             [ Floating Tilemap ]
  72.  
  73.     There's a floating tilemap made of vertical colums composed of 2x16
  74.     "sprites". Each 32 consecutive "sprites" define a column. Each column
  75.     has a variable horizontal position and a vertical scrolling value
  76.     (see the Sprite Control Registers).
  77.  
  78.  
  79.         Spriteram_2 + 0x800.w
  80.  
  81.                         f--- ---- ---- ----        Flip X
  82.                         -e-- ---- ---- ----        Flip Y
  83.                         --dc b--- ---- ----        -
  84.                         ---- --98 7654 3210        Code (Lower bits)
  85.  
  86.         Spriteram_2 + 0xc00.w
  87.  
  88.                         fedc b--- ---- ----        Color
  89.                         ---- -a-- ---- ----        ?Code (Upper Bits)?
  90.                         ---- --9- ---- ----        Code (Upper Bits)
  91.                         ---- ---8 7654 3210        -
  92.  
  93.         Spriteram   + 0x400.w
  94.  
  95.                         fedc ba98 ---- ----        -
  96.                         ---- ---- 7654 3210        Y
  97.  
  98.  
  99.  
  100.  
  101.                         [ Sprites Control Registers ]
  102.  
  103.  
  104.         Spriteram   + 0x601.b
  105.  
  106.                         7--- ----        0
  107.                         -6-- ----        Flip Screen
  108.                         --5- ----        0
  109.                         ---4 ----        1 (Sprite Enable?)
  110.                         ---- 3---        ?
  111.                         ---- -210        0
  112.  
  113.         Spriteram   + 0x603.b
  114.  
  115.                         7--- ----        0
  116.                         -6-- ----        Sprite Bank
  117.                         --5- ----        1 (?)
  118.                         ---4 ----        0
  119.                         ---- 3210        Columns To Draw (1 is the special value for 16?)
  120.  
  121.         Spriteram   + 0x605.b
  122.  
  123.                         7654 3210        High Bit Of X For Columns 7-0
  124.  
  125.         Spriteram   + 0x607.b
  126.  
  127.                         7654 3210        High Bit Of X For Columns f-8
  128.  
  129.  
  130.  
  131.  
  132. ***************************************************************************/
  133. #include "vidhrdw/generic.h"
  134.  
  135. /* Variables only used here */
  136. static struct tilemap *tilemap_0,*tilemap_1, *tilemap_2,*tilemap_3;
  137.  
  138. /* Variables that driver has access to */
  139. unsigned char *seta_vram_0, *seta_vram_1, *seta_vctrl_0;
  140. unsigned char *seta_vram_2, *seta_vram_3, *seta_vctrl_2;
  141. unsigned char *seta_vregs;
  142.  
  143. int seta_tiles_offset;    // tiles banking, can be 0 or $4000
  144.  
  145.  
  146. WRITE_HANDLER( seta_vregs_w )
  147. {
  148.     COMBINE_WORD_MEM(&seta_vregs[offset], data);
  149.     switch (offset)
  150.     {
  151.         case 0:
  152.             if (!(data & 0x00ff0000))
  153.             {    // typical value: 002c
  154.                 coin_lockout_w(0, (data >> 0) & 1 );
  155.                 coin_lockout_w(1, (data >> 1) & 1 );
  156.             }
  157.             break;
  158.  
  159.         case 2:    // Handled in vh_screenrefresh:
  160.                 // bit 0: swap layers order
  161.                 // bit 1: ?
  162.             break;
  163.  
  164.         case 4:    // ?
  165.             break;
  166.     }
  167. }
  168.  
  169.  
  170.  
  171.  
  172. /***************************************************************************
  173.  
  174.                         Callbacks for the TileMap code
  175.  
  176.                               [ Tiles Format ]
  177.  
  178. Offset + 0x0000:
  179.                     f--- ---- ---- ----        Flip X
  180.                     -e-- ---- ---- ----        Flip Y
  181.                     --dc ba98 7654 3210        Code
  182.  
  183. Offset + 0x1000:
  184.  
  185.                     fedc ba98 765- ----        -
  186.                     ---- ---- ---4 3210        Color
  187.  
  188.  
  189. ***************************************************************************/
  190. #define DIM_NX        (64)
  191. #define DIM_NY        (32)
  192.  
  193. #define SETA_TILEMAP(_n_) \
  194. static void get_tile_info_##_n_( int tile_index ) \
  195. { \
  196.     int code =    READ_WORD(&seta_vram_##_n_[ tile_index * 2]); \
  197.     int attr =    READ_WORD(&seta_vram_##_n_[ tile_index * 2 + DIM_NX*DIM_NY*2]); \
  198.     SET_TILE_INFO( 1 + _n_/2, seta_tiles_offset + (code & 0x3fff), attr & 0x1f ); \
  199.     tile_info.flags = TILE_FLIPXY( code >> (16-2) ); \
  200. } \
  201. \
  202. WRITE_HANDLER( seta_vram_##_n_##_w ) \
  203. { \
  204.     COMBINE_WORD_MEM(&seta_vram_##_n_[offset],data); \
  205.     offset %= DIM_NX * DIM_NY * 2; \
  206.     tilemap_mark_tile_dirty(tilemap_##_n_, offset/2 ); \
  207. }
  208.  
  209. SETA_TILEMAP(0)
  210. SETA_TILEMAP(1)
  211. SETA_TILEMAP(2)
  212. SETA_TILEMAP(3)
  213.  
  214.  
  215. /* 2 layers */
  216. int seta_vh_start_2_layers(void)
  217. {
  218.     /* Each layer consists of 2 tilemaps: only one can be displayed
  219.        at any given time */
  220.  
  221.     /* layer 0 */
  222.     tilemap_0 = tilemap_create(    get_tile_info_0,
  223.                                 tilemap_scan_rows,
  224.                                 TILEMAP_TRANSPARENT,
  225.                                 16,16,
  226.                                 DIM_NX,DIM_NY );
  227.  
  228.     tilemap_1 = tilemap_create(    get_tile_info_1,
  229.                                 tilemap_scan_rows,
  230.                                 TILEMAP_TRANSPARENT,
  231.                                 16,16,
  232.                                 DIM_NX,DIM_NY );
  233.  
  234.  
  235.     /* layer 1 */
  236.     tilemap_2 = tilemap_create(    get_tile_info_2,
  237.                                 tilemap_scan_rows,
  238.                                 TILEMAP_TRANSPARENT,
  239.                                 16,16,
  240.                                 DIM_NX,DIM_NY );
  241.  
  242.     tilemap_3 = tilemap_create(    get_tile_info_3,
  243.                                 tilemap_scan_rows,
  244.                                 TILEMAP_TRANSPARENT,
  245.                                 16,16,
  246.                                 DIM_NX,DIM_NY );
  247.  
  248.     if (tilemap_0 && tilemap_1 && tilemap_2 && tilemap_3)
  249.     {
  250.         tilemap_set_scroll_rows(tilemap_0,1);
  251.         tilemap_set_scroll_cols(tilemap_0,1);
  252.         tilemap_0->transparent_pen = 0;
  253.  
  254.         tilemap_set_scroll_rows(tilemap_1,1);
  255.         tilemap_set_scroll_cols(tilemap_1,1);
  256.         tilemap_1->transparent_pen = 0;
  257.  
  258.         tilemap_set_scroll_rows(tilemap_2,1);
  259.         tilemap_set_scroll_cols(tilemap_2,1);
  260.         tilemap_2->transparent_pen = 0;
  261.  
  262.         tilemap_set_scroll_rows(tilemap_3,1);
  263.         tilemap_set_scroll_cols(tilemap_3,1);
  264.         tilemap_3->transparent_pen = 0;
  265.  
  266.         tilemap_set_scrolldx(tilemap_0, -0x01, 0x00);    // see zingzip test mode
  267.         tilemap_set_scrolldx(tilemap_1, -0x01, 0x00);
  268.         tilemap_set_scrolldx(tilemap_2, -0x01, 0x00);
  269.         tilemap_set_scrolldx(tilemap_3, -0x01, 0x00);
  270.  
  271.         tilemap_set_scrolldy(tilemap_0, 0x00, 0x00);
  272.         tilemap_set_scrolldy(tilemap_1, 0x00, 0x00);
  273.         tilemap_set_scrolldy(tilemap_2, 0x00, 0x00);
  274.         tilemap_set_scrolldy(tilemap_3, 0x00, 0x00);
  275.  
  276.         return 0;
  277.     }
  278.     else return 1;
  279. }
  280.  
  281.  
  282. /* 1 layer */
  283. int seta_vh_start_1_layer(void)
  284. {
  285.     /* Each layer consists of 2 tilemaps: only one can be displayed
  286.        at any given time */
  287.  
  288.     /* layer 0 */
  289.     tilemap_0 = tilemap_create(    get_tile_info_0,
  290.                                 tilemap_scan_rows,
  291.                                 TILEMAP_TRANSPARENT,
  292.                                 16,16,
  293.                                 DIM_NX,DIM_NY );
  294.  
  295.     tilemap_1 = tilemap_create(    get_tile_info_1,
  296.                                 tilemap_scan_rows,
  297.                                 TILEMAP_TRANSPARENT,
  298.                                 16,16,
  299.                                 DIM_NX,DIM_NY );
  300.  
  301.  
  302.     /* NO layer 1 */
  303.     tilemap_2 = 0;
  304.     tilemap_3 = 0;
  305.  
  306.     if (tilemap_0 && tilemap_1)
  307.     {
  308.         tilemap_set_scroll_rows(tilemap_0,1);
  309.         tilemap_set_scroll_cols(tilemap_0,1);
  310.         tilemap_0->transparent_pen = 0;
  311.  
  312.         tilemap_set_scroll_rows(tilemap_1,1);
  313.         tilemap_set_scroll_cols(tilemap_1,1);
  314.         tilemap_1->transparent_pen = 0;
  315.  
  316.         tilemap_set_scrolldx(tilemap_0, 0x00, 0x00); // see metafox test mode
  317.         tilemap_set_scrolldx(tilemap_1, 0x00, 0x00);
  318.  
  319.         tilemap_set_scrolldy(tilemap_0, 0x00, 0x00);
  320.         tilemap_set_scrolldy(tilemap_1, 0x00, 0x00);
  321.  
  322.         return 0;
  323.     }
  324.     else return 1;
  325. }
  326.  
  327.  
  328.  
  329.  
  330.  
  331. /* layer 0 is 6 bit per pixel, but the color code has a 16 colors granularity */
  332. void zingzip_vh_init_palette(unsigned char *palette, unsigned short *colortable,const unsigned char *color_prom)
  333. {
  334.     int color, pen;
  335.     for( color = 0; color < 32; color++ )
  336.         for( pen = 0; pen < 64; pen++ )
  337.             colortable[color * 64 + pen + 32*16*2] = ((color * 16 + pen)%(32*16)) + 32*16*2;
  338. }
  339.  
  340. /* 6 bit layer. The colors are still WRONG */
  341. void usclssic_vh_init_palette(unsigned char *palette, unsigned short *colortable,const unsigned char *color_prom)
  342. {
  343.     int color, pen;
  344.     for( color = 0; color < 32; color++ )
  345.         for( pen = 0; pen < 64; pen++ )
  346.             colortable[color * 64 + pen + 512] = (((color & 0xf) * 16 + pen)%(512));
  347. }
  348.  
  349.  
  350.  
  351.  
  352.  
  353.  
  354.  
  355.  
  356.  
  357.  
  358.  
  359. /***************************************************************************
  360.  
  361.  
  362.                                 Sprites Drawing
  363.  
  364.  
  365. ***************************************************************************/
  366.  
  367.  
  368. void seta_mark_sprite_color(void)
  369. {
  370.     int offs, col;
  371.     int xoffs, yoffs;
  372.  
  373.     int color_granularity    =    Machine->gfx[0]->color_granularity;
  374.     int color_codes_start    =    Machine->drv->gfxdecodeinfo[0].color_codes_start;
  375.     int total_color_codes    =    Machine->drv->gfxdecodeinfo[0].total_color_codes;
  376.  
  377.     int xmin = Machine->drv->visible_area.min_x - (16 - 1);
  378.     int xmax = Machine->drv->visible_area.max_x;
  379.     int ymin = Machine->drv->visible_area.min_y - (16 - 1);
  380.     int ymax = Machine->drv->visible_area.max_y;
  381.  
  382.     /* Floating tilemap made of sprites */
  383.  
  384.     int ctrl    =    READ_WORD(&spriteram[0x600]);
  385.     int ctrl2    =    READ_WORD(&spriteram[0x602]);
  386.     int flip    =    ctrl & 0x40;
  387.     int numcol    =    ctrl2 & 0x000f;
  388.  
  389.     unsigned char *spriteram1 = spriteram_2 + ((ctrl2 & 0x40) ? 0x2000 : 0);
  390.  
  391.     /* Number of columns to draw - the value 1 seems special, meaning:
  392.        draw every column */
  393.     if (numcol == 1)    numcol = 16;
  394.  
  395.  
  396.     for ( col = 0 ; col < numcol; col ++ )
  397.     {
  398.         for ( offs = 0 ; offs < 0x40; offs += 2 )
  399.         {
  400.             int    color    =    READ_WORD(&spriteram1[col * 0x40 + offs + 0xc00]);
  401.             color        =    ( color >> (16-5) ) % total_color_codes;
  402.             memset(&palette_used_colors[color_granularity * color + color_codes_start + 1],PALETTE_COLOR_USED,color_granularity - 1);
  403.         }
  404.     }
  405.  
  406.  
  407.     /* Normal sprites */
  408.  
  409.     xoffs    =    flip ? 0x10 : 0x11;
  410.     yoffs    =    flip ? 0x06 : 0x06;
  411.  
  412.     for ( offs = 0x400-2 ; offs >= 0; offs -= 2 )
  413.     {
  414. //        int    code    =    READ_WORD(&spriteram1[offs + 0x000]);
  415.         int    x        =    READ_WORD(&spriteram1[offs + 0x400]);
  416.         int    y        =    READ_WORD(&spriteram [offs + 0x000]);
  417.         int color    =    ( x >> (16-5) ) % total_color_codes;
  418.  
  419.         x = (x + xoffs) & 0x1ff;
  420.         y = (ymax+1) - ((y + yoffs) & 0x0ff);
  421.  
  422.         /* Visibility check. No need to account for sprites flipping */
  423.         if ((x < xmin) || (x > xmax))    continue;
  424.         if ((y < ymin) || (y > ymax))    continue;
  425.  
  426.         memset(&palette_used_colors[color_granularity * color + color_codes_start + 1],PALETTE_COLOR_USED,color_granularity - 1);
  427.     }
  428. }
  429.  
  430.  
  431.  
  432.  
  433. static void seta_draw_sprites_map(struct osd_bitmap *bitmap)
  434. {
  435.     int offs, col;
  436.     int xoffs, yoffs;
  437.  
  438.     int total_color_codes    =    Machine->drv->gfxdecodeinfo[0].total_color_codes;
  439.  
  440.     int ctrl    =    READ_WORD(&spriteram[0x600]);
  441.     int ctrl2    =    READ_WORD(&spriteram[0x602]);
  442.  
  443.     int flip    =    ctrl & 0x40;
  444.     int numcol    =    ctrl2 & 0x000f;
  445.  
  446.     unsigned char *spriteram1 = spriteram_2 + ((ctrl2 & 0x40) ? 0x2000 : 0);
  447.  
  448.     int upper    =    ( READ_WORD(&spriteram[0x604]) & 0xFF ) +
  449.                     ( READ_WORD(&spriteram[0x606]) & 0xFF ) * 256;
  450.  
  451. //    int max_x    =    Machine->drv->screen_width  - 16;
  452. //    int max_y    =    Machine->drv->visible_area.max_y+1;    // see pic of metafox
  453.  
  454.     xoffs    =    flip ? 0x10 : 0x10;    // see wrofaero test mode: made of sprites map
  455.     yoffs    =    flip ? 0x09 : 0x07;
  456.  
  457.     /* Number of columns to draw - the value 1 seems special, meaning:
  458.        draw every column */
  459.     if (numcol == 1)    numcol = 16;
  460.  
  461.  
  462.     /* The first column is the frontmost, see twineagl test mode */
  463.     for ( col = numcol - 1 ; col >= 0; col -- )
  464.     {
  465.         int    x    =    READ_WORD(&spriteram[col * 0x20 + 0x08 + 0x400]) & 0xff;
  466.         int    y    =    READ_WORD(&spriteram[col * 0x20 + 0x00 + 0x400]) & 0xff;
  467.  
  468.         /* draw this column */
  469.         for ( offs = 0 ; offs < 0x40; offs += 2 )
  470.         {
  471.             int    code    =    READ_WORD(&spriteram1[col * 0x40 + offs + 0x800]);
  472.             int    color    =    READ_WORD(&spriteram1[col * 0x40 + offs + 0xc00]);
  473.  
  474.             int    flipx    =    code & 0x8000;
  475.             int    flipy    =    code & 0x4000;
  476.  
  477.             int bank    =    color & 0x0200;
  478.  
  479.             int sx        =      x + xoffs  + ((offs/2) & 1) * 16;
  480.             int sy        =    -(y + yoffs) + ((offs/2) / 2) * 16;
  481.  
  482.             if (upper & (1 << col))    sx += 256;
  483.  
  484.             if (flip)
  485.             {
  486. //                x = 0x200 - y;
  487. //                y = 0x100 - y;
  488.                 flipx = !flipx;
  489. //                flipy = !flipy;
  490.             }
  491.  
  492.             color    =    ( color >> (16-5) ) % total_color_codes;
  493.             code    =    (code & 0x3fff) + (bank ? 0x4000 : 0);
  494.  
  495. #define DRAWTILE(_x_,_y_)  \
  496.             drawgfx(bitmap,Machine->gfx[0], \
  497.                     code, \
  498.                     color, \
  499.                     flipx, flipy, \
  500.                     _x_,_y_, \
  501.                     &Machine->drv->visible_area,TRANSPARENCY_PEN,0);
  502.  
  503.             DRAWTILE(sx - 0x000, sy + 0x000)
  504.             DRAWTILE(sx - 0x200, sy + 0x000)
  505.             DRAWTILE(sx - 0x000, sy + 0x100)
  506.             DRAWTILE(sx - 0x200, sy + 0x100)
  507.  
  508.         }
  509.  
  510.     /* next column */
  511.     }
  512.  
  513. }
  514.  
  515.  
  516.  
  517. static void seta_draw_sprites(struct osd_bitmap *bitmap)
  518. {
  519.     int offs;
  520.     int xoffs, yoffs;
  521.  
  522.     int total_color_codes    =    Machine->drv->gfxdecodeinfo[0].total_color_codes;
  523.  
  524.     int ctrl    =    READ_WORD(&spriteram[0x600]);
  525.     int ctrl2    =    READ_WORD(&spriteram[0x602]);
  526.  
  527.     int flip    =    ctrl & 0x40;
  528.     unsigned char *spriteram1 = spriteram_2 + ((ctrl2 & 0x40) ? 0x2000 : 0);
  529.  
  530. //    int max_x    =    Machine->drv->screen_width  - 16;
  531.     int max_y    =    Machine->drv->visible_area.max_y+1;    // see pic of metafox
  532.  
  533.     seta_draw_sprites_map(bitmap);
  534.  
  535.     xoffs    =    flip ? 0x10 : 0x11;    // see downtown test mode: made of normal sprites
  536.     yoffs    =    flip ? 0x06 : 0x06;
  537.  
  538.     for ( offs = 0x400-2 ; offs >= 0; offs -= 2 )
  539.     {
  540.         int    code    =    READ_WORD(&spriteram1[offs + 0x000]);
  541.         int    x        =    READ_WORD(&spriteram1[offs + 0x400]);
  542.         int    y        =    READ_WORD(&spriteram [offs + 0x000]);
  543.  
  544.         int    flipx    =    code & 0x8000;
  545.         int    flipy    =    code & 0x4000;
  546.  
  547.         int bank    =     x & 0x0200;
  548.         int color    =    ( x >> (16-5) ) % total_color_codes;
  549.  
  550.         if (flip)
  551.         {
  552. //            x = max_x - x;
  553.             y = max_y - y;
  554.             flipx = !flipx;        flipy = !flipy;
  555.         }
  556.  
  557.         code = (code & 0x3fff) + (bank ? 0x4000 : 0);
  558.  
  559.         drawgfx(bitmap,Machine->gfx[0],
  560.                 code,
  561.                 color,
  562.                 flipx, flipy,
  563.                 (x + xoffs) & 0x1ff,
  564.                 max_y - ((y + yoffs) & 0x0ff),
  565.                 &Machine->drv->visible_area,TRANSPARENCY_PEN,0);
  566.     }
  567.  
  568. }
  569.  
  570.  
  571.  
  572.  
  573.  
  574. /***************************************************************************
  575.  
  576.                                 Screen Drawing
  577.  
  578. ***************************************************************************/
  579.  
  580. /* For games without tilemaps */
  581. void seta_vh_screenrefresh_no_layers(struct osd_bitmap *bitmap,int full_refresh)
  582. {
  583.     palette_init_used_colors();
  584.     seta_mark_sprite_color();
  585.     palette_recalc();
  586.     osd_clearbitmap(Machine->scrbitmap);
  587.     seta_draw_sprites(bitmap);
  588. }
  589.  
  590.  
  591.  
  592. /* For games with 1 or 2 tilemaps */
  593. void seta_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
  594. {
  595.     int layers_ctrl = -1;
  596.     int enab_0, enab_1, x_0, x_1, y_0, y_1;
  597.  
  598.     int order    =     0;
  599.     int flip    =    READ_WORD(&spriteram[0x600]) & 0x40;
  600.  
  601.     tilemap_set_flip(ALL_TILEMAPS, flip ? (TILEMAP_FLIPX|TILEMAP_FLIPY) : 0 );
  602.  
  603.     x_0        =    READ_WORD(&seta_vctrl_0[0]);
  604.     y_0        =    READ_WORD(&seta_vctrl_0[2]);
  605.     enab_0    =    READ_WORD(&seta_vctrl_0[4]);
  606.  
  607.     /* Only one tilemap per layer is enabled! */
  608.     tilemap_set_enable(tilemap_0, (!(enab_0 & 0x0008)) /*&& (enab_0 & 0x0001)*/ );
  609.     tilemap_set_enable(tilemap_1, ( (enab_0 & 0x0008)) /*&& (enab_0 & 0x0001)*/ );
  610.  
  611.     /* the hardware wants different scroll values when flipped */
  612.  
  613.     if (flip)    {    x_0 = -402 - x_0;    y_0 = y_0 - 0x100;    }
  614.     tilemap_set_scrollx (tilemap_0, 0, x_0);
  615.     tilemap_set_scrollx (tilemap_1, 0, x_0);
  616.     tilemap_set_scrolly (tilemap_0, 0, y_0);
  617.     tilemap_set_scrolly (tilemap_1, 0, y_0);
  618.  
  619.     if (tilemap_2)
  620.     {
  621.         x_1        =    READ_WORD(&seta_vctrl_2[0]);
  622.         y_1        =    READ_WORD(&seta_vctrl_2[2]);
  623.         enab_1    =    READ_WORD(&seta_vctrl_2[4]);
  624.  
  625.         tilemap_set_enable(tilemap_2, (!(enab_1 & 0x0008)) /*&& (enab_1 & 0x0001)*/ );
  626.         tilemap_set_enable(tilemap_3, ( (enab_1 & 0x0008)) /*&& (enab_1 & 0x0001)*/ );
  627.  
  628.         if (flip)    {    x_1 = -402 - x_1;    y_1 = y_1 - 0x100;    }
  629.         tilemap_set_scrollx (tilemap_2, 0, x_1);
  630.         tilemap_set_scrollx (tilemap_3, 0, x_1);
  631.         tilemap_set_scrolly (tilemap_2, 0, y_1);
  632.         tilemap_set_scrolly (tilemap_3, 0, y_1);
  633.  
  634.         order    =    READ_WORD(&seta_vregs[2]);
  635.     }
  636.  
  637.  
  638. #ifdef MAME_DEBUG
  639. if (keyboard_pressed(KEYCODE_Z))
  640. {
  641.     int msk = 0;
  642.     char buf[80];
  643.     if (keyboard_pressed(KEYCODE_Q))    msk |= 1;
  644.     if (keyboard_pressed(KEYCODE_W))    msk |= 2;
  645.     if (keyboard_pressed(KEYCODE_A))    msk |= 8;
  646.     if (msk != 0) layers_ctrl &= msk;
  647.  
  648.     if (tilemap_2)
  649.         sprintf(buf,"%04X-%04X-%04X %04X-%04X",
  650.                     READ_WORD(&seta_vregs[0]),
  651.                     READ_WORD(&seta_vregs[2]),
  652.                     READ_WORD(&seta_vregs[4]),
  653.  
  654.                     READ_WORD(&seta_vctrl_0[4]),
  655.                     READ_WORD(&seta_vctrl_2[4])
  656.                 );
  657.     else
  658.         sprintf(buf,"%04X",    READ_WORD(&seta_vctrl_0[4])    );
  659.  
  660.     usrintf_showmessage(buf);
  661. }
  662. #endif
  663.  
  664.     tilemap_update(ALL_TILEMAPS);
  665.  
  666.     palette_init_used_colors();
  667.  
  668.     seta_mark_sprite_color();
  669.  
  670.     if (palette_recalc())    tilemap_mark_all_pixels_dirty(ALL_TILEMAPS);
  671.  
  672.     tilemap_render(ALL_TILEMAPS);
  673.  
  674.     osd_clearbitmap(Machine->scrbitmap);
  675.  
  676.     if (order & 1)    // swap the layers?
  677.     {
  678.         if (tilemap_2)
  679.         {
  680.             if (layers_ctrl & 2)    tilemap_draw(bitmap, tilemap_2, TILEMAP_IGNORE_TRANSPARENCY);
  681.             if (layers_ctrl & 2)    tilemap_draw(bitmap, tilemap_3, TILEMAP_IGNORE_TRANSPARENCY);
  682.         }
  683.  
  684.         if (order & 2)    // layer-sprite priority?
  685.         {
  686.             if (layers_ctrl & 8)    seta_draw_sprites(bitmap);
  687.             if (layers_ctrl & 1)    tilemap_draw(bitmap, tilemap_0,  0);
  688.             if (layers_ctrl & 1)    tilemap_draw(bitmap, tilemap_1,  0);
  689.         }
  690.         else
  691.         {
  692.             if (layers_ctrl & 1)    tilemap_draw(bitmap, tilemap_0,  0);
  693.             if (layers_ctrl & 1)    tilemap_draw(bitmap, tilemap_1,  0);
  694.             if (layers_ctrl & 8)    seta_draw_sprites(bitmap);
  695.         }
  696.     }
  697.     else
  698.     {
  699.         if (layers_ctrl & 1)    tilemap_draw(bitmap, tilemap_0,  TILEMAP_IGNORE_TRANSPARENCY);
  700.         if (layers_ctrl & 1)    tilemap_draw(bitmap, tilemap_1,  TILEMAP_IGNORE_TRANSPARENCY);
  701.  
  702.         if (order & 2)    // layer-sprite priority?
  703.         {
  704.             if (layers_ctrl & 8)    seta_draw_sprites(bitmap);
  705.  
  706.             if (tilemap_2)
  707.             {
  708.                 if (layers_ctrl & 2)    tilemap_draw(bitmap, tilemap_2,  0);
  709.                 if (layers_ctrl & 2)    tilemap_draw(bitmap, tilemap_3,  0);
  710.             }
  711.         }
  712.         else
  713.         {
  714.             if (tilemap_2)
  715.             {
  716.                 if (layers_ctrl & 2)    tilemap_draw(bitmap, tilemap_2,  0);
  717.                 if (layers_ctrl & 2)    tilemap_draw(bitmap, tilemap_3,  0);
  718.             }
  719.  
  720.             if (layers_ctrl & 8)    seta_draw_sprites(bitmap);
  721.         }
  722.     }
  723.  
  724. }
  725.